<template>
	<view class="main">
		<form @submit="formSubmit">
			<view class="form">
				<view class="pwd">
					<input type="text" name="pwd" value="" placeholder="请输入验证码" />
					<u-toast ref="uToast"></u-toast>
							<u-verification-code :seconds="seconds"  ref="uCode" 
							@change="codeChange"></u-verification-code>
					<text @click="getCode()">{{tips}}</text>
				</view>
				<view class="pwd">
					<input type="password" name="npwd" value="" placeholder="请输入新密码" />
				</view>
				<view class="pwd">
					<input type="password" name="z_npwd" value="" placeholder="再次输入新密码" />
				</view>
				<view class="ps">
					请设置6位及以上包含数字字母和特殊符号中至少两种组合的密码
				</view>
			</view>
			<view class="button">
				<button type="error" form-type="submit">确定</button>
			</view>
		
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '获取验证码',
				// refCode: null,
				seconds: 60,
				phone:'',
			}
		},
		onLoad() {
			// console.log(JSON.parse(uni.getStorageSync('userInfo')));
			this.phone=JSON.parse(uni.getStorageSync('userInfo'))
		},
		
		methods: {
			
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						this.yanzhengma()
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
					
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
	yanzhengma(){
		global.$http.request({
			url: '/api/rider_login/forget_yzm',
			data: {
				phone:this.phone.mobile
			}
		}).then(res => {
			console.log(res);
			if(res.data.code==1){
					uni.showToast({
						title: res.data.msg,
						icon: "none",
						mask: true,
						duration: 1000
					})
			}
		})
	},
			formSubmit: function(e) {
				console.log(e.detail.value)
				var info = e.detail.value
				global.$http.request({
					url: '/api/rider_user/forget',
					data: {
						code: info.pwd,
						pwd: info.npwd,
						pwd: info.z_npwd,
						phone:this.phone.mobile   
					}
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							mask: true,
							duration: 1000
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC;
		background-color: #f7f7f7;

		.main {
			margin-top: 20rpx;

			.form {
				.pwd {
					background-color: #FFFFFF;
					background: rgba(255, 255, 255, 0.39);
					opacity: 1;
					padding: 34rpx 30rpx;
					margin-bottom: 4rpx;

					input {
						font-size: 32rpx;
						font-weight: 400;
						// color: #999999;
						opacity: 1;
					}
				}

				.ps {
					margin-top: 32rpx;
					text-align: center;
					font-size: 22rpx;
					font-weight: 400;
					line-height: 34rpx;
					color: #BBBBBB;
					opacity: 1;
				}

			}

			.form :first-child {
				display: flex;
				align-items: center;
				justify-content: space-between;

				text {
					font-size: 30rpx;
					font-weight: 400;
					line-height: 44rpx;
					color: #507DAF;
					opacity: 1;
					padding-left: 30rpx;
					border-left: 1rpx solid #E9E9E9;
				}
			}

			.button {
				width: 400rpx;
				border-radius: 50rpx !important;
				margin: 110rpx auto 38rpx auto;
				overflow: hidden;
				font-size: 30rpx;
				font-weight: 400;
				opacity: 1;
				background-color: #FF482F;

				button {
					color: #fff !important;
				}
			}
		}
	}
</style>
